import * as React from "react";
import { Button } from "antd";
import {
  IReducerState_TableFilter,
  IReducerState_Form
} from "../../store/reducer";
import { connect } from "react-redux";
import { Reducers } from "../../../../../App";
import { Dispatch } from "redux";
import { formShow_addAct } from "../../store/actions";

interface IPropsState {
  filter: IReducerState_TableFilter;
  form: IReducerState_Form;
}

interface IPropsDispatch {
  show: (form: IReducerState_Form) => void;
}

interface IExtra {}

type TProps = IPropsState & IPropsDispatch & IExtra;

const Action: React.FC<TProps> = props => {
  const { filter, show, form } = props;

  function onClick() {
    show({ ...form, visible_add: true });
  }

  return (
    <Button
      onClick={() => onClick()}
      disabled={filter.selectedKeys.length > 0 ? true : false}
      type="primary"
      size="small"
    >
      添加
    </Button>
  );
};

function mapStateToProps(state: Reducers): IPropsState {
  const reducer = state.manageOrderReducer;
  return {
    filter: reducer.table_filter,
    form: reducer.form_info
  };
}

const mapDispatchToProps = (dispatch: Dispatch): IPropsDispatch => ({
  show(form: IReducerState_Form) {
    const action = formShow_addAct(form);
    dispatch(action);
  }
});

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(Action);
